<template>
  <div id="cluereport">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item>干部监督填报</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>{{unitname}}</h1>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        >
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth" :index="indexMethod">
        </el-table-column>
        <el-table-column prop="projectTitle" label="项目名称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="类型" width="120" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ fTypeName(scope.row.projectType) }}
          </template>
        </el-table-column>
        <el-table-column prop="beginDate" label="填报开始时间" width="120" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
          {{scope.row.beginDate}}
          </template>
        </el-table-column>
        <el-table-column prop="endDate" label="填报结束时间" width="120" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
          {{scope.row.endDate}}
          </template>
        </el-table-column>
        <el-table-column prop="projectState" label="状态" width="80" align="center">
          <template slot-scope="scope">
            {{stateid2name(scope.row.reportState)}}
          </template>
        </el-table-column>
        <el-table-column prop="backReason" label="退回原因" width="300" align="left" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.backReason}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="250" align="center">
          <template slot-scope="scope">
            <el-button @click="customEdit(scope.row.reportDataId)" type="primary" size="mini" style="margin:10px 0 10px 5px">开始填报</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      unitname: '',
      listLoading: false,
      tableHeight: 100,
      list: [
      ],
      pageNum: 1,
      pageSize: 20,
      totalnum: 10,
      changeSizeFlag: false,
      typeNameList: ['因私出国（境）']
    }
  },
  methods: {
    fTypeName (index) {
      return this.typeNameList[index]
    },
    stateid2name (id) {
      switch (id) {
        case 0:
          return '未提交'
        case 1:
          return '已提交'
        case 2:
          return '退回'
      }
    },
    edit (id) {
      this.$router.push('unitDetail/' + id)
    },
    customEdit (id) {
      this.noticeStorageKey = `noticeShown_${id}`
      localStorage.setItem(this.noticeStorageKey, 'false')
      this.$router.push('customUnitDetail/' + id)
    },
    indexMethod (index) {
      return index + (this.pageNum - 1) * this.pageSize + 1
    },
    handleSelectionChange (val) {
      this.ids = val
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = 'asc'
      } else {
        this.Isace = 'desc'
      }
      this.getList()
    },
    getList () {
      let para = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.supervisionAPI + `api/statsReportData/queryTodoProjectPage`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
            if (response.data.result.current > response.data.result.pages && response.data.result.pages !== 0) {
              this.pageNum = response.data.result.pages
              this.getList()
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 235

      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.unitname = localStorage.getItem('Otherunitname')
    this.getList()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#cluereport .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #cluereport .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
